import React, { Component } from 'react'
import {ListBox} from '../../components'
import UpdateWaverulePage from './Update'
import { Modal } from 'antd';

export default class ListWaverulePage extends Component {
    constructor(props) {
        super(props);
        //行操作列表
        this.rowOperation = [
        ];

        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'addWaverule',
                showName: '新增',
                iconClass: 'plus'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete'
            }
        ];


        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'ListWaveruleColumnConfig',
            data: [
                {
                    showName: 'waveRuleId',
                    columnName: 'waveRuleId',
                    columnHidden:true,
                    foreverHidden: true
                },{ showName: '波次规则编号',
                    columnName: 'waveRuleNo',
                    columnWidth: 130
                },{
                    showName: '波次规则描述',
                    columnName: 'waveRuleDesc',
                    columnWidth: 130
                },{
                    showName: '仓库代码',
                    columnName: 'whCode'
                },{
                    showName: '区域',
                    columnName: 'regionCode'
                },{
                    showName: '库区编码',
                    columnName: 'areaCode'
                },{
                    showName: '路线',
                    columnName: 'route'
                },{
                    showName: '送达方编码',
                    columnName: 'sdfCd'
                },{
                    showName: '承运人',
                    columnName: 'carrier'
                },{
                    showName: '订单类型',
                    columnName: 'orderType'
                },{
                    showName: '客户',
                    columnName: 'custCode'
                },{
                    showName: '商家',
                    columnName: 'bussinesType'
                },{
                    showName: '运输方式',
                    columnName: 'tranType'
                },{
                    showName: '按配车单分组',
                    columnName: 'vehicleGroup',
                    columnWidth: 130
                },{
                    showName: '单品',
                    columnName: 'sku'
                },{
                    showName: '订单数量上限',
                    columnName: 'orderCount',
                    columnWidth: 130
                },{
                    showName: '订单数量下限',
                    columnName: 'orderCountLow',
                    columnWidth: 130
                },{
                    showName: '固定收货人数量',
                    columnName: 'recevierCount',
                    columnWidth: 130
                },{
                    showName: '体积限定',
                    columnName: 'volumeLimit'
                },{
                    showName: '重量限定',
                    columnName: 'weightLimit'
                },{
                    showName: '最长等待时间分',
                    columnName: 'waitMin',
                    columnWidth: 130
                },{
                    showName: '优先级',
                    columnName: 'priority'
                },{
                    showName: '分配规则',
                    columnName: 'shelvesRule'
                },{
                    showName: '集货位推荐类型',
                    columnName: 'gatherLocType',
                    columnWidth: 130
                },{
                    showName: '直接分配库存',
                    columnName: 'directDistRepertory',
                    columnWidth: 130
                },{
                    showName: '订单时间',
                    columnName: 'orderTime'
                },{
                    showName: '应发货时间窗口',
                    columnName: 'orderSendTime',
                    columnWidth: 130
                },{
                    showName: '固定产品数量',
                    columnName: 'fixProductCount',
                    columnWidth: 130
                },{
                    showName: '最小提总数',
                    columnName: 'minCount'
                },{
                    showName: '总件数设定',
                    columnName: 'allCountLimit'
                },{
                    showName: '波次数',
                    columnName: 'waveCount'
                },{
                    showName: '整箱约束',
                    columnName: 'completeBox'
                },{
                    showName: '是否面签拣货',
                    columnName: 'visaPick',
                    columnWidth: 130
                }
                ,{
                    showName: '状态属性',
                    columnName: 'status'
                }
                ,{
                    showName: '执行间隔',
                    columnName: 'intervals',
                }
                ,{
                    showName: '执行开始时间',
                    columnName: 'carriedOutStart',
                    columnWidth: 130,
                }
                ,{
                    showName: '执行结束时间',
                    columnName: 'carriedOutEnd',
                    columnWidth: 130
                }
                ,{
                    showName: '最近执行时间',
                    columnName: 'recentExecuteTime',
                    columnWidth: 130
                },{
                    showName: '下次执行时间',
                    columnName: 'nextTime',
                    columnWidth: 130
                },{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate'
                },{
                    showName: '更新人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '更新时间',
                    columnName: 'gmtModified'
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '仓库代码',
                name:'whCode',
                type: 'input',
                url: null
            },{
                showName: '区域编码',
                name:'regionCode',
                type: 'input',
                url: null
            },{
                showName: '库区编码',
                name:'areaCode',
                type: 'input',
                url: null
            },{
                showName: '波次编号',
                name:'waveRuleNo',
                type: 'input',
                url: null
            },{
                showName: '波次描述',
                name:'waveRuleDesc',
                type: 'input',
                url: null
            },{
                showName: '路线',
                name:'route',
                type: 'input',
                url: null
            },{
                showName: '送达方编码',
                name:'sdfCd',
                type: 'input',
                url: null
            },{
                showName: '承运人',
                name:'carrier',
                type: 'input',
                url: null
            },{
                showName: '订单类型',
                name:'orderType',
                type: 'input',
                url: null
            },{
                showName: '客户',
                name:'custCode',
                type: 'input',
                url: null
            },{
                showName: '商家',
                name:'bussinesType',
                type: 'input',
                url: null
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'gmtCreateMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin'
            }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }else if(strHandles === 'addWaverule'){
            this.addWaveruleHandle();
        }
    }
    // 增加用户
    addWaveruleHandle = () => {
        this.refs.updateWaverule.addWaveruleHandle();
    }
    editHandle = (rowObj) => {

        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else {
            this.refs.updateWaverule.getFormData[1].disable = true;
            this.refs.updateWaverule.editHandle(rowObj[0].data);
        }

    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else {
            this.refs.updateWaverule.deleteHandle(rowObj[0].data)
        }
    }


    //刷新列表
    refreshHandle = () => {
        this.refs.listWaverule.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'listWaverule'
                    title="波次规则"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/base/data/waverule/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />

                <UpdateWaverulePage
                        ref="updateWaverule"
                        refreshHandle = {this.refreshHandle}
                />


            </div>
        )
    }
}
